package org.proyectosinapsis.Sinapsis;

/**.
 * User: Alexander Simoes
 * Company: CoralVision Systems
 * Date: 9/13/12
 */

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

public class RecoverPasswordActivity extends Activity {

	//Function that checks if all EditText in the layout are not empty
	//It displays a floating text asking the user for the input
	//True if it finds at least one that is empty
	private boolean checkForm() {

		ViewGroup group = (ViewGroup) findViewById(R.id.registerForm);
		String errorMsg = getString(R.string.emptyForm);
		int strLenght = errorMsg.length();

		for (int i = 0, count = group.getChildCount(); i < count; ++i) {
			View view = group.getChildAt(i);
			if (view instanceof EditText) {
				String str = ((EditText)view).getText().toString();
				if (str.trim().equals("")) {
					errorMsg = errorMsg + "\n" + ((EditText)view).getHint().toString();
				}
			}
		}

		if (errorMsg.length()!=strLenght) {
			Toast.makeText(this, errorMsg, Toast.LENGTH_SHORT).show();
			return true;
		}

		return false;
	}

	//Function that checks that email have correct format (Only works in android 2.2+)
	//True if there's an error
	private boolean checkEmail() {
		String email = ((EditText)findViewById(R.id.rec_email)).getText().toString();
		if (!android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
			Toast.makeText(this, getString(R.string.wrongEmailFormat), Toast.LENGTH_SHORT).show();
			return true;
		}
		return false;
	}

	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Set View to register.xml
        setContentView(R.layout.recover_password);

        ImageView loginScreen = (ImageView) findViewById(R.id.back);

        // Listening to Login Screen link
        loginScreen.setOnClickListener(new View.OnClickListener() {

            public void onClick(View arg0) {
                // Closing recovery password screen
                // Switching to Login Screen/closing register screen
                finish();
            }
        });
    }
}


//ToDo: because send mail in sinapsis system is failing, decide if recover password action will be used in this app
//ToDo: add action to the button, and verify is there isn't empty fields in the form